package com.gege.homework1;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Proxy;

/**
 * 使用 Java 里的动态代理，实现一个简单的 AOP
 *
 * @author gechenpeng
 * @date 2021-04-12
 */
@Slf4j
public class JdkDynamicProxyDemo {

    public static void main(String[] args) throws Exception {
        People people = new Student("花花");

        People proxy = (People) Proxy.newProxyInstance(people.getClass().getClassLoader(),
                people.getClass().getInterfaces(), new LogHandler(people));

        proxy.eat();
        proxy.sleepo();
    }
}
